//
//  ChangeUserName.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/17.
//

import SwiftUI

struct ChangeUserName: View {
    @State var userName:String = ""
    var body: some View {
        //        NavigationStack {
        VStack {
            ScrollView(showsIndicators: false) {
                userIdInput
                tipsTitle
                confirmBtnView
            }
            
        }
        .onTapGesture {
            UIApplication.shared.endEditing()
        }
        .navigationTitle("修改名称")
//        .navigationBarTitleDisplayMode(.inline)
        .frame(maxWidth: .infinity)
        .background(Color("color_bg"))
        .navigationBack()
    }
    
    var tipsTitle:some View {
        HStack {
            Text("输入您想要修改的用户名称")
                .modifier(YWTextModifer(fontSize: 14, fontWeight: .light, design: .rounded, color: .colorTextSub))
            Spacer()
        }
            .padding(.top,4)
            .padding(.horizontal,14)
    }
    
    var userIdInput:some View {
        HStack {
            TextField("请输入用户名称", text: $userName)
            Image(systemName: "xmark.circle.fill")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 24, height: 24)
                .accentColor(Color("color_text_main"))
                .shakeTapGes {
                    clean()
                }
        }
        .padding(.horizontal,10)
        .frame(height: 50)
        .background(.white)
        .cornerRadius(14)
        .padding(.horizontal,10)
        .padding(.top,20)
    }
    
    var confirmBtnView:some View {
        ShakeButton(label: Text("修 改"), textColor: .colorTextMain, fontSize: 16, fontWeight: .bold) {
            confirmBtnClick()
        }.padding(.top,60)
    }
    
    private func clean() {
        userName = ""
    }
    
    private func confirmBtnClick() {
       
        if userName.isEmpty {
            YWToast.show(text: "用户名不能为空")
            return
        }
    }
}
